#!/usr/bin/python

##################################
#                                #
#  David Lladro - S2 Grupo       #
#     Noviembre 2011             #
#  Mail: david.lladro@gmail.com  #
#  Twitter: @davidlladro         #
#                                #
##################################

# paquetes necesarios 
import urllib2, subprocess,time

# Host y archivo 
url_base = "http://www.gameburnworld.com/pcgamefixes"
url_base2 = "http://www.gameburnworld.com/gp/gamefixes/"
url_descarga = "http://cdn.naxpgaming.com/gbw/files/"
num_juegos = 0
categoria = ['numbers','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for cat in categoria:
	url = url_base + str(cat)+ ".shtml"
	try:
		f = urllib2.urlopen(url)
		web = f.readlines()
		f.close()
		download = str(web).split("gp/gamefixes/")
		for j in download:
			arg = j.split("\"")[0]
			if ".shtml" in arg:
				url2 = url_base2 + arg
				num_juegos = int(num_juegos) + 1
				f = urllib2.urlopen(url2)
				web2 = f.read()
				f.close()
				download2 = str(web2).split("dl.php")[1]
				download2 = str(download2).split("\"")[0]
				nombre = str(download2).split("file=")[1]
				if "?file" in download2:
					url3 = url_descarga + nombre
					conversion = subprocess.Popen(['wget', '-U', 'Mozilla', url3, '-O', nombre], stderr=subprocess.STDOUT,stdout = subprocess.PIPE )
                			out, err = conversion.communicate()
					print "Descargando " + nombre		
	except:
		print "No hay mas url"

print "Numero total de cracks = " + str(num_juegos)

